package io.renren.modules.lanling.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.lanling.entity.SchoolPicEntity;
import io.renren.modules.lanling.service.SchoolPicService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 学校图库
 *
 * @author LANLING
 * @email lanling@gmail.com
 * @date 2018-11-30 10:34:41
 */
@RestController
@RequestMapping("lanling/schoolpic")
public class SchoolPicController {
    @Autowired
    private SchoolPicService schoolPicService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("lanling:schoolpic:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = schoolPicService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lanling:schoolpic:info")
    public R info(@PathVariable("id") Integer id) {
        SchoolPicEntity schoolPic = schoolPicService.selectById(id);
        return R.ok().put("schoolPic", schoolPic);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("lanling:schoolpic:save")
    public R save(@RequestBody SchoolPicEntity schoolPic) {
        schoolPicService.insert(schoolPic);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("lanling:schoolpic:update")
    public R update(@RequestBody SchoolPicEntity schoolPic) {
        ValidatorUtils.validateEntity(schoolPic);

        schoolPicService.updateById(schoolPic);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("lanling:schoolpic:delete")
    public R delete(@RequestBody Integer[] ids) {
        schoolPicService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam("schoolId") Integer schoolId) {
        EntityWrapper<SchoolPicEntity> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("school_id", schoolId);

        List<SchoolPicEntity> list = schoolPicService.selectList(entityWrapper);
        return R.ok().put("list", list);
    }
}
